<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the Articlemusic class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single Articlemusic object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a ArticlemusicMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 * 
	 * @package My Application
	 * @subpackage MetaControls
	 * property-read Articlemusic $Articlemusic the actual Articlemusic data class being edited
	 * property QLabel $IdControl
	 * property-read QLabel $IdLabel
	 * property QListBox $ReferenceIDControl
	 * property-read QLabel $ReferenceIDLabel
	 * property QTextBox $ArtistControl
	 * property-read QLabel $ArtistLabel
	 * property QTextBox $LabelControl
	 * property-read QLabel $LabelLabel
	 * property QFloatTextBox $NumberOfDiscsControl
	 * property-read QLabel $NumberOfDiscsLabel
	 * property QDateTimePicker $ReleaseDateControl
	 * property-read QLabel $ReleaseDateLabel
	 * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class ArticlemusicMetaControlGen extends QBaseClass {
		// General Variables
		protected $objArticlemusic;
		protected $objParentObject;
		protected $strTitleVerb;
		protected $blnEditMode;

		// Controls that allow the editing of Articlemusic's individual data fields
		protected $lblId;
		protected $lstReferenceIDObject;
		protected $txtArtist;
		protected $txtLabel;
		protected $txtNumberOfDiscs;
		protected $calReleaseDate;

		// Controls that allow the viewing of Articlemusic's individual data fields
		protected $lblReferenceID;
		protected $lblArtist;
		protected $lblLabel;
		protected $lblNumberOfDiscs;
		protected $lblReleaseDate;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * ArticlemusicMetaControl to edit a single Articlemusic object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single Articlemusic object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlemusicMetaControl
		 * @param Articlemusic $objArticlemusic new or existing Articlemusic object
		 */
		 public function __construct($objParentObject, Articlemusic $objArticlemusic) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this ArticlemusicMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked Articlemusic object
			$this->objArticlemusic = $objArticlemusic;

			// Figure out if we're Editing or Creating New
			if ($this->objArticlemusic->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
		 * edit, or if we are also allowed to create a new one, etc.
		 * 
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlemusicMetaControl
		 * @param integer $intId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing Articlemusic object creation - defaults to CreateOrEdit
 		 * @return ArticlemusicMetaControl
		 */
		public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intId)) {
				$objArticlemusic = Articlemusic::Load($intId);

				// Articlemusic was found -- return it!
				if ($objArticlemusic)
					return new ArticlemusicMetaControl($objParentObject, $objArticlemusic);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a Articlemusic object with PK arguments: ' . $intId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new ArticlemusicMetaControl($objParentObject, new Articlemusic());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlemusicMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Articlemusic object creation - defaults to CreateOrEdit
		 * @return ArticlemusicMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::PathInfo(0);
			return ArticlemusicMetaControl::Create($objParentObject, $intId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlemusicMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Articlemusic object creation - defaults to CreateOrEdit
		 * @return ArticlemusicMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::QueryString('intId');
			return ArticlemusicMetaControl::Create($objParentObject, $intId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QLabel lblId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblId_Create($strControlId = null) {
			$this->lblId = new QLabel($this->objParentObject, $strControlId);
			$this->lblId->Name = QApplication::Translate('Id');
			if ($this->blnEditMode)
				$this->lblId->Text = $this->objArticlemusic->Id;
			else
				$this->lblId->Text = 'N/A';
			return $this->lblId;
		}

		/**
		 * Create and setup QListBox lstReferenceIDObject
		 * @param string $strControlId optional ControlId to use
		 * @return QListBox
		 */
		public function lstReferenceIDObject_Create($strControlId = null) {
			$this->lstReferenceIDObject = new QListBox($this->objParentObject, $strControlId);
			$this->lstReferenceIDObject->Name = QApplication::Translate('Reference I D Object');
			$this->lstReferenceIDObject->Required = true;
			if (!$this->blnEditMode)
				$this->lstReferenceIDObject->AddItem(QApplication::Translate('- Select One -'), null);
			$objReferenceIDObjectArray = Articlecore::LoadAll();
			if ($objReferenceIDObjectArray) foreach ($objReferenceIDObjectArray as $objReferenceIDObject) {
				$objListItem = new QListItem($objReferenceIDObject->__toString(), $objReferenceIDObject->Id);
				if (($this->objArticlemusic->ReferenceIDObject) && ($this->objArticlemusic->ReferenceIDObject->Id == $objReferenceIDObject->Id))
					$objListItem->Selected = true;
				$this->lstReferenceIDObject->AddItem($objListItem);
			}
			return $this->lstReferenceIDObject;
		}

		/**
		 * Create and setup QLabel lblReferenceID
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblReferenceID_Create($strControlId = null) {
			$this->lblReferenceID = new QLabel($this->objParentObject, $strControlId);
			$this->lblReferenceID->Name = QApplication::Translate('Reference I D Object');
			$this->lblReferenceID->Text = ($this->objArticlemusic->ReferenceIDObject) ? $this->objArticlemusic->ReferenceIDObject->__toString() : null;
			$this->lblReferenceID->Required = true;
			return $this->lblReferenceID;
		}

		/**
		 * Create and setup QTextBox txtArtist
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtArtist_Create($strControlId = null) {
			$this->txtArtist = new QTextBox($this->objParentObject, $strControlId);
			$this->txtArtist->Name = QApplication::Translate('Artist');
			$this->txtArtist->Text = $this->objArticlemusic->Artist;
			$this->txtArtist->TextMode = QTextMode::MultiLine;
			return $this->txtArtist;
		}

		/**
		 * Create and setup QLabel lblArtist
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblArtist_Create($strControlId = null) {
			$this->lblArtist = new QLabel($this->objParentObject, $strControlId);
			$this->lblArtist->Name = QApplication::Translate('Artist');
			$this->lblArtist->Text = $this->objArticlemusic->Artist;
			return $this->lblArtist;
		}

		/**
		 * Create and setup QTextBox txtLabel
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtLabel_Create($strControlId = null) {
			$this->txtLabel = new QTextBox($this->objParentObject, $strControlId);
			$this->txtLabel->Name = QApplication::Translate('Label');
			$this->txtLabel->Text = $this->objArticlemusic->Label;
			$this->txtLabel->MaxLength = Articlemusic::LabelMaxLength;
			return $this->txtLabel;
		}

		/**
		 * Create and setup QLabel lblLabel
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblLabel_Create($strControlId = null) {
			$this->lblLabel = new QLabel($this->objParentObject, $strControlId);
			$this->lblLabel->Name = QApplication::Translate('Label');
			$this->lblLabel->Text = $this->objArticlemusic->Label;
			return $this->lblLabel;
		}

		/**
		 * Create and setup QFloatTextBox txtNumberOfDiscs
		 * @param string $strControlId optional ControlId to use
		 * @return QFloatTextBox
		 */
		public function txtNumberOfDiscs_Create($strControlId = null) {
			$this->txtNumberOfDiscs = new QFloatTextBox($this->objParentObject, $strControlId);
			$this->txtNumberOfDiscs->Name = QApplication::Translate('Number Of Discs');
			$this->txtNumberOfDiscs->Text = $this->objArticlemusic->NumberOfDiscs;
			return $this->txtNumberOfDiscs;
		}

		/**
		 * Create and setup QLabel lblNumberOfDiscs
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblNumberOfDiscs_Create($strControlId = null, $strFormat = null) {
			$this->lblNumberOfDiscs = new QLabel($this->objParentObject, $strControlId);
			$this->lblNumberOfDiscs->Name = QApplication::Translate('Number Of Discs');
			$this->lblNumberOfDiscs->Text = $this->objArticlemusic->NumberOfDiscs;
			$this->lblNumberOfDiscs->Format = $strFormat;
			return $this->lblNumberOfDiscs;
		}

		/**
		 * Create and setup QDateTimePicker calReleaseDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calReleaseDate_Create($strControlId = null) {
			$this->calReleaseDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calReleaseDate->Name = QApplication::Translate('Release Date');
			$this->calReleaseDate->DateTime = $this->objArticlemusic->ReleaseDate;
			$this->calReleaseDate->DateTimePickerType = QDateTimePickerType::Date;
			return $this->calReleaseDate;
		}

		/**
		 * Create and setup QLabel lblReleaseDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblReleaseDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblReleaseDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblReleaseDate->Name = QApplication::Translate('Release Date');
			$this->strReleaseDateDateTimeFormat = $strDateTimeFormat;
			$this->lblReleaseDate->Text = sprintf($this->objArticlemusic->ReleaseDate) ? $this->objArticlemusic->ReleaseDate->__toString($this->strReleaseDateDateTimeFormat) : null;
			return $this->lblReleaseDate;
		}

		protected $strReleaseDateDateTimeFormat;




		/**
		 * Refresh this MetaControl with Data from the local Articlemusic object.
		 * @param boolean $blnReload reload Articlemusic from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objArticlemusic->Reload();

			if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objArticlemusic->Id;

			if ($this->lstReferenceIDObject) {
					$this->lstReferenceIDObject->RemoveAllItems();
				if (!$this->blnEditMode)
					$this->lstReferenceIDObject->AddItem(QApplication::Translate('- Select One -'), null);
				$objReferenceIDObjectArray = Articlecore::LoadAll();
				if ($objReferenceIDObjectArray) foreach ($objReferenceIDObjectArray as $objReferenceIDObject) {
					$objListItem = new QListItem($objReferenceIDObject->__toString(), $objReferenceIDObject->Id);
					if (($this->objArticlemusic->ReferenceIDObject) && ($this->objArticlemusic->ReferenceIDObject->Id == $objReferenceIDObject->Id))
						$objListItem->Selected = true;
					$this->lstReferenceIDObject->AddItem($objListItem);
				}
			}
			if ($this->lblReferenceID) $this->lblReferenceID->Text = ($this->objArticlemusic->ReferenceIDObject) ? $this->objArticlemusic->ReferenceIDObject->__toString() : null;

			if ($this->txtArtist) $this->txtArtist->Text = $this->objArticlemusic->Artist;
			if ($this->lblArtist) $this->lblArtist->Text = $this->objArticlemusic->Artist;

			if ($this->txtLabel) $this->txtLabel->Text = $this->objArticlemusic->Label;
			if ($this->lblLabel) $this->lblLabel->Text = $this->objArticlemusic->Label;

			if ($this->txtNumberOfDiscs) $this->txtNumberOfDiscs->Text = $this->objArticlemusic->NumberOfDiscs;
			if ($this->lblNumberOfDiscs) $this->lblNumberOfDiscs->Text = $this->objArticlemusic->NumberOfDiscs;

			if ($this->calReleaseDate) $this->calReleaseDate->DateTime = $this->objArticlemusic->ReleaseDate;
			if ($this->lblReleaseDate) $this->lblReleaseDate->Text = sprintf($this->objArticlemusic->ReleaseDate) ? $this->objArticlemusic->__toString($this->strReleaseDateDateTimeFormat) : null;

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////





		///////////////////////////////////////////////
		// PUBLIC ARTICLEMUSIC OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's Articlemusic instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveArticlemusic() {
			try {
				// Update any fields for controls that have been created
				if ($this->lstReferenceIDObject) $this->objArticlemusic->ReferenceID = $this->lstReferenceIDObject->SelectedValue;
				if ($this->txtArtist) $this->objArticlemusic->Artist = $this->txtArtist->Text;
				if ($this->txtLabel) $this->objArticlemusic->Label = $this->txtLabel->Text;
				if ($this->txtNumberOfDiscs) $this->objArticlemusic->NumberOfDiscs = $this->txtNumberOfDiscs->Text;
				if ($this->calReleaseDate) $this->objArticlemusic->ReleaseDate = $this->calReleaseDate->DateTime;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the Articlemusic object
				$this->objArticlemusic->Save();

				// Finally, update any ManyToManyReferences (if any)
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's Articlemusic instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteArticlemusic() {
			$this->objArticlemusic->Delete();
		}		



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'Articlemusic': return $this->objArticlemusic;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to Articlemusic fields -- will be created dynamically if not yet created
				case 'IdControl':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'IdLabel':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'ReferenceIDControl':
					if (!$this->lstReferenceIDObject) return $this->lstReferenceIDObject_Create();
					return $this->lstReferenceIDObject;
				case 'ReferenceIDLabel':
					if (!$this->lblReferenceID) return $this->lblReferenceID_Create();
					return $this->lblReferenceID;
				case 'ArtistControl':
					if (!$this->txtArtist) return $this->txtArtist_Create();
					return $this->txtArtist;
				case 'ArtistLabel':
					if (!$this->lblArtist) return $this->lblArtist_Create();
					return $this->lblArtist;
				case 'LabelControl':
					if (!$this->txtLabel) return $this->txtLabel_Create();
					return $this->txtLabel;
				case 'LabelLabel':
					if (!$this->lblLabel) return $this->lblLabel_Create();
					return $this->lblLabel;
				case 'NumberOfDiscsControl':
					if (!$this->txtNumberOfDiscs) return $this->txtNumberOfDiscs_Create();
					return $this->txtNumberOfDiscs;
				case 'NumberOfDiscsLabel':
					if (!$this->lblNumberOfDiscs) return $this->lblNumberOfDiscs_Create();
					return $this->lblNumberOfDiscs;
				case 'ReleaseDateControl':
					if (!$this->calReleaseDate) return $this->calReleaseDate_Create();
					return $this->calReleaseDate;
				case 'ReleaseDateLabel':
					if (!$this->lblReleaseDate) return $this->lblReleaseDate_Create();
					return $this->lblReleaseDate;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to Articlemusic fields
					case 'IdControl':
						return ($this->lblId = QType::Cast($mixValue, 'QControl'));
					case 'ReferenceIDControl':
						return ($this->lstReferenceIDObject = QType::Cast($mixValue, 'QControl'));
					case 'ArtistControl':
						return ($this->txtArtist = QType::Cast($mixValue, 'QControl'));
					case 'LabelControl':
						return ($this->txtLabel = QType::Cast($mixValue, 'QControl'));
					case 'NumberOfDiscsControl':
						return ($this->txtNumberOfDiscs = QType::Cast($mixValue, 'QControl'));
					case 'ReleaseDateControl':
						return ($this->calReleaseDate = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>